using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Manage_shop_product_recommend : Member, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected Literal ltrOther;
	protected Literal ltrScore;
	protected DataList DataListEliteProduct;
	protected TextBox KeyWords;
	protected Button Button1;
	protected GridView GVProduct;
	protected Button ButElite;
	protected ObjectDataSource EliteProductSource;
	public int ShopID = 0;
	public string m_flag = "0";
	public string proTypeWhere = "";
	public string promotionmanage = "0";
	private string tabMenu = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public string TabMenu
	{
		get
		{
			if (base.Request.QueryString["TabMenu"] != null)
			{
				this.tabMenu = base.Request.QueryString["TabMenu"].Trim();
			}
			else
			{
				this.tabMenu = "tabOther";
			}
			return this.tabMenu;
		}
		set
		{
			this.tabMenu = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ShopID = base.user.ShopID;
		if (this.ShopID <= 0)
		{
			this.WriteErrMsg("友情提示", Language.GetMemberMsg("Common/NoShop", new string[0]), "../Member/Shop_OpenShop.aspx");
		}
		this.EliteProductSource.SelectParameters["SalerID"].DefaultValue = base.user.UserID.ToString();
		if (!base.IsPostBack)
		{
			if (StaticFunApp.ShopConfig["ShowScore"].IsNull(new object[0]) == "1")
			{
				string groupPower = base.user.GetGroupPower("GroupPower");
				if (groupPower.Contains("promotionmanage"))
				{
					this.promotionmanage = "1";
				}
			}
			this.ShowPanelDisplay(this.TabMenu);
			this.GetGvProductList();
			this.EliteProductSource.SelectParameters["proWhere"].DefaultValue = this.proTypeWhere;
			this.GetEliteProductList();
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (!(DisplayName == "tabOther"))
			{
				if (DisplayName == "tabScore")
				{
					this.m_flag = "5";
					this.proTypeWhere = " and ProductType=5 ";
				}
			}
			else
			{
				this.m_flag = "0";
				this.proTypeWhere = " and ProductType<>5 ";
			}
		}
		Cookie.SaveCookie("Contacter_m_flag", this.m_flag, 0, "");
	}
	private void GetEliteProductList()
	{
		for (int i = 0; i < this.DataListEliteProduct.Items.Count; i++)
		{
			Literal literal = (Literal)this.DataListEliteProduct.Items[i].FindControl("Label3");
			HiddenField hiddenField = (HiddenField)this.DataListEliteProduct.Items[i].FindControl("hfProductTypeElite");
			HiddenField hiddenField2 = (HiddenField)this.DataListEliteProduct.Items[i].FindControl("hfNeedPresentExpElite");
			if (hiddenField != null)
			{
				if (hiddenField.Value == "5")
				{
					if (!string.IsNullOrEmpty(hiddenField2.Value))
					{
						literal.Text = hiddenField2.Value;
					}
				}
			}
		}
	}
	protected void DataListEliteProduct_ItemDataBound(object sender, DataListItemEventArgs e)
	{
		HtmlImage htmlImage = (HtmlImage)e.Item.FindControl("Editeproductimage");
		if (!File.Exists(base.Server.MapPath(htmlImage.Src.Replace("/", "\\"))))
		{
			htmlImage.Src = "../Images/show_nopic.gif";
		}
	}
	protected void DataListEliteProduct_ItemCommand(object source, DataListCommandEventArgs e)
	{
		if (e.CommandName == "cancelEli")
		{
			int productID = Convert.ToInt32(e.CommandArgument);
			Shop_Product shop_Product = new Shop_Product(this.conn);
			shop_Product.SetProductElite(false, productID);
			this.DataListEliteProduct.DataBind();
			this.GetEliteProductList();
			this.GetGvProductList();
		}
	}
	protected void Button3_Click(object sender, EventArgs e)
	{
		this.GetGvProductList();
	}
	protected void ButElite_Click(object sender, EventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("chk_select"));
		string[] array = text.Split(new char[]
		{
			','
		});
		if (text != "")
		{
			for (int i = 0; i < array.Length; i++)
			{
				string sql = "update HLShop_Product set IsElite=1 where ProductID in(" + Convert.ToInt32(array[i]) + ")";
				this.conn.Execute(sql);
			}
		}
		else
		{
			this.WriteErrMsg("", "未选中推荐商品项，请您选择要推荐的商品项！", "");
		}
		this.GetGvProductList();
		this.DataListEliteProduct.DataBind();
		this.GetEliteProductList();
	}
	private void GetGvProductList()
	{
		this.ShowPanelDisplay(this.TabMenu);
		string text = string.Concat(new object[]
		{
			"Select * From [HLShop_Product] Where DateDiff(s,'",
			DateTime.Now,
			"',BeginDate)<=0 and DateDiff(s,'",
			DateTime.Now,
			"',EndDate)>0 and IsElite=0 and EnableSingleSell=1 and EnableSale=1 and ([SalerID]=",
			base.user.UserID,
			")",
			this.proTypeWhere
		});
		if (this.KeyWords.Text.Trim().ToString() != "")
		{
			text = text + " and [ProductName] like '%" + this.KeyWords.Text.Trim().ToString() + "%'";
		}
		text += " order by ProductID desc";
		DataTable dataTable = this.conn.GetDataTable(text);
		this.GVProduct.DataSource = dataTable;
		this.GVProduct.DataBind();
		for (int i = 0; i < this.GVProduct.Rows.Count; i++)
		{
			Literal literal = (Literal)this.GVProduct.Rows[i].FindControl("CurrentPrice");
			HiddenField hiddenField = (HiddenField)this.GVProduct.Rows[i].FindControl("hfProductType");
			HiddenField hiddenField2 = (HiddenField)this.GVProduct.Rows[i].FindControl("hfNeedPresentExp");
			if (hiddenField != null)
			{
				if (hiddenField.Value == "5")
				{
					if (!string.IsNullOrEmpty(hiddenField2.Value))
					{
						literal.Text = hiddenField2.Value;
					}
				}
			}
		}
	}
	protected void GVProduct_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GVProduct.Rows)
		{
			HtmlImage htmlImage = (HtmlImage)gridViewRow.FindControl("productimage");
			if (!File.Exists(base.Server.MapPath(htmlImage.Src.Replace("/", "\\"))))
			{
				htmlImage.Src = "../Images/show_nopic.gif";
			}
		}
	}
	protected void GVProduct_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GVProduct.PageIndex = e.NewPageIndex;
		this.GetGvProductList();
	}
	protected void GVProduct_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
}
